<template>
	<!--修改商家页面-->
    <view class="content">
        <view class="details-from">
            <form  v-model="Rise">
                <view class="ad-contant" >
                    <view>商家基本信息:</view>
                </view>
                
               
                <view class="uni-details-list">
                    <view class="title">商家名称:</view>
					<view>
                    <input class="uni-input-02" name="input" placeholder="请输入商家名称" v-model="merchant.merchantName" />
					</view>
                </view>
				
                <view class="ad-button">
                    <button form-type="submit" @tap="saveMerchant" class="button">提交</button>
                    <button type="default" form-type="reset" class="button">清空数据</button>
                </view>
				
            </form>
        </view>
    </view>
</template>
<script>
    export default {
        data() {
            return {
				merchant: {
					merchantName: '',
					email: '',
					phone: '',
				},

            }
        },
		onLoad () {
				//根据商家id获取商家数据
				var me = this;
				var cache = uni.getStorageSync("merchantInfo")
				console.log("cache="+JSON.stringify(cache))
				uni.request({
					url: me.$ServerUrl + '/invoice/api/merchant/getMerchantById', //获取商家信息
					header: {
						'content-type': 'application/json' // 默认值
					},
					data: {
						 id:cache.id
					},
					method: "GET",
					success(res) {
						console.log(res);
						me.merchant = res.data
						console.log("-------获取成功-----");
					}
				})
		},
        methods: {
			//保存用户数据
			saveMerchant(){
				var me = this;
				var cache = uni.getStorageSync("merchantInfo")
				console.log(cache.keys)
				uni.request({
					url: me.$ServerUrl + '/invoice/api/merchant/saveMerchant', //修改商户信息
					header: {
						'content-type': 'application/json' // 默认值
					},
					data: {
						id:cache.id,
						merchantName:this.merchant.merchantName,
					},
					method: "POST",
					success(res) {
						console.log(res);
						console.log("-------修改成功-----");
						uni.showToast({
							title: '修改成功',
							duration: 2000,
							success() {
								uni.redirectTo({
									url:"../index"
								})
							}
						});

					}
				})
				
			}
			
			
			
			
			}
        }

</script>

<style>
	page{
		width: 100%;
		height: 100%;
		background-color: #e1e5eb;
	}
    .content {
    	display: flex;
    	flex-direction: column;
    	align-items: center;
    	justify-content: center;
    }
    .details-from{
    	width: 100%;
    	height: 100%;
    	margin: 20px;
    }
    .uni-details-list{
    	border: 1px solid #F1F1F1;
    	display: flex;
    	background-color: #ffffff;
    	align-items: center;
    	padding: 10px;
    	margin-bottom: 5px;
    	border-radius: 10px;
		margin: 10px;
    }
	.title{
		font-size: 16px;
	}
	.uni-input-01{
		font-size: 16px;
		margin-left: 35px;
	}
	.uni-input-02{
		font-size: 14px;
		margin-left: 10px;
	}
	.button{
		background-color: #4c9800;
		color: #ffffff;
		width: 100%;
		margin: 10px;
		font-size: 16px;
	}
	.ad-button{
		display: flex;
	}
	.ad-contant{
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		font-size: 18px;
		margin: 10px;
	}
</style>